using RayDen.Library.Components.Surface;
using RayDen.Library.Core;
using RayDen.Library.Core.Primitives;

namespace RayDen.RayEngine.Engines.PathSpaceMLT
{
    public class ImplicitLightPathSamplingTechnique : PathSamplingTechnique
    {
        public ImplicitLightPathSamplingTechnique(MetropolisPathSampler ps) : base(ps)
        {
        }

        public override bool Match(bool isLight, bool isVolume, BsdfEvent hitEvent)
        {
            return isLight;
        }

        public override void Process(ref RayHit rh, ref Vector wo, out bool finishPath, out float pdf)
        {
            var lt = PathSampler.scene.GetLightByIndex((int)rh.Index);
            pdf = 0;
            if (lt != null)
            {
                var le = lt.Emittance(ref wo, out pdf);//* hitInfo.Color 
                //Radiance += Throughput * le;
                if (!le.IsBlack())
                    PathSampler.mutate = true;

                PathSampler.Radiance.MAdd(ref PathSampler.Throughput, ref le);
            }
            finishPath = true;
        }

    }
}